package com.zed.api.common.adpt;

/**
 * 通过服务资源库实现{@link Adaptable}的抽象类
 *
 * @author Zed
 */
public abstract class AdaptObject implements Adaptable {

    /**
     *
     */
    public AdaptObject() {

    }

    @Override
    public <A> A adapt(Class<A> adaptType) {
        return this.doAdaptWithServiceRepository(adaptType);
    }

    /**
     * 使用ServiceRepository进行适配
     *
     * @param <A>
     * @param adaptType {@link Class},要适配的类型
     * @return {@link A}
     */
    @SuppressWarnings("unchecked")
    protected <A> A doAdaptWithServiceRepository(Class<A> adaptType) {
        return AdaptObjectUtils.getAdaptObject((Class<Object>) this.getHostType(), adaptType, this);
    }

    protected Class<?> getHostType() {
        return this.getClass();
    }
}
